//
//  PersonalHomePageCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/24.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "PersonalHomePageCell.h"
#import "ShareNewsPraiseView.h"



@interface PersonalHomePageCell ()
/**动态文字*/
@property (nonatomic,strong)UILabel*dynamicLabel;
/**动态图片*/
@property (nonatomic,strong)UIImageView*dynamicImage;
/**底部小按钮视图*/
@property (nonatomic,strong)ShareNewsPraiseView *bottomView;
/**<#属性#>*/
@property (nonatomic,strong)UIView*bgView;
/**<#属性#>*/
@property (nonatomic,strong)UIButton*seleBtn;
@end

@implementation PersonalHomePageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)reloadCell:(BOOL)isRight{
    self.seleBtn.hidden = !isRight;
    CGFloat left = 0;
    if (isRight) {
        left = 40;
    }
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(left);
    }];

}
-(void)setModel:(PersonalHomePageModel *)model{
    _model = model;
    self.topView.userName.text = model.userName;
    self.topView.iconImage.image = IMAGE_NAMED(model.userImage);
    [self.bottomView.shareBtn setTitle:model.zhuanfaNum forState:UIControlStateNormal];
    [self.bottomView.newsBtn setTitle:model.xiaoxiNum forState:UIControlStateNormal];
    [self.bottomView.praiseBtn setTitle:model.zanNum forState:UIControlStateNormal];
    self.bottomView.praiseBtn.selected = model.isZan;
//    self.dynamicLabel.text = model.contex;
    [TitleTool setDynamicTitle:model.contex Label:self.dynamicLabel];
    self.dynamicImage.image = IMAGE_NAMED(model.rightImage);
    
    self.seleBtn.selected = model.isSelecte;

}
-(void)createUI{
    
    self.seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"delete_check_selecet") forState:UIControlStateSelected];
    self.seleBtn.hidden = YES;
    
    kWeakSelf(weakSelf);
    [self.seleBtn addActionHandler:^{
        weakSelf.seleBtn.selected = !weakSelf.seleBtn.selected;
        BlockSafeRun(weakSelf.selecteAction,weakSelf.seleBtn.selected);
    }];
    
    [self addSubview:self.seleBtn];
    
    [self.seleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
    }];

    self.bgView = UIView.new;
    self.bgView.userInteractionEnabled = YES;
    
    [self addSubview:self.bgView];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    self.topView= [[PersonalHomeCellUserView alloc] initWithFrame:CGRectZero];
    self.bottomView=[[ShareNewsPraiseView alloc] initWithFrame:CGRectZero];
    [self.bottomView.shareBtn setImage:IMAGE_NAMED(@"image_2") forState:UIControlStateNormal];
    
    self.dynamicImage = UIImageView.new;
    self.dynamicImage.image = IMAGE_NAMED(@"dynamicDefut");
    
    [self.bgView addSubview:self.topView];
    [self.bgView addSubview:self.dynamicLabel];
    [self.bgView addSubview:self.bottomView];
    [self.bgView addSubview:self.dynamicImage];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];
    [self.dynamicLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.topView.mas_bottom);
    }];
    [self.dynamicImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(210);
        make.top.mas_equalTo(self.dynamicLabel.mas_bottom).offset(8);
    }];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.mas_equalTo(self.dynamicImage.mas_bottom);
    }];
}

-(UILabel*)dynamicLabel{
    if(!_dynamicLabel){
        _dynamicLabel=[UILabel new];
        _dynamicLabel.font = SYSTEMFONT(18);
        _dynamicLabel.textColor = UIColorFromRGB(0x273323);
        _dynamicLabel.numberOfLines = 2;
        _dynamicLabel.text = @"今天晚上做了法式薄煎饼，简单容易上手，老人孩子都喜欢吃，美味又健康，在家....";

    }
    return _dynamicLabel;
}

@end
